﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;
using Castle.MicroKernel.Registration;
using Castle.Windsor;
using FaceSharp.Api;
using FaceSharp.MVC.Code.Facebook;

namespace FaceSharp.MVC
{
    // Note: For instructions on enabling IIS6 or IIS7 classic mode, 
    // visit http://go.microsoft.com/?LinkId=9394801

    public class MvcApplication : System.Web.HttpApplication
    {
       // public IWindsorContainer Container;

        public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

            routes.MapRoute(
                "Default", // Route name
                "{controller}/{action}/{id}", // URL with parameters
                new { controller = "Default", action = "Index", id = UrlParameter.Optional }, // Parameter defaults
                new string[] {"FaceSharp.MVC.Controllers"}
            );
        }


        
        protected void Session_Start()
        {
            
        }
        protected void Application_Start()
        {
            //container = new WindsorContainer();
            //container.Register(Component.For<IFacebookCore>().LifeStyle.PerWebRequest.ImplementedBy<FacebookCore>());
            //container.AddComponent("IFacebookCore", typeof(FacebookCore));

            var enableSqlDependency = bool.Parse(ConfigurationManager.AppSettings["EnableSqlDependency"]);
            if (enableSqlDependency) SqlDependency.Start(ConfigurationManager.ConnectionStrings["ShareThriftConnectionString"].ConnectionString);
            AreaRegistration.RegisterAllAreas();
            RegisterRoutes(RouteTable.Routes);
        }

        protected void Application_End()
        {
            var enableSqlDependency = bool.Parse(ConfigurationManager.AppSettings["EnableSqlDependency"]);
            if (enableSqlDependency) SqlDependency.Stop(ConfigurationManager.ConnectionStrings["ShareThriftConnectionString"].ConnectionString); 
        }
    }
}